package com.petRescueCenter.demo.pet.entity.dto;

import java.util.Date;

import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.petRescueCenter.demo.common.enumPackage.PetTypeEmun;
import com.petRescueCenter.demo.pet.entity.Pet;

import io.swagger.annotations.ApiModelProperty;

public class PetDTO {
	@ApiModelProperty(name = "id", value = "宠物id", required = false)
	private Long id;
	@ApiModelProperty(name = "ownerId", value = "主人id", required = false)
	private Long ownerId;
	@ApiModelProperty(name = "img", value = "宠物图片", required = false)
	private String img;
	@ApiModelProperty(name = "name", value = "宠物名字", required = false)
	private String name;
	@ApiModelProperty(name = "ownerName", value = "主人名字", required = false)
	private String ownerName;
	@ApiModelProperty(name = "feature", value = "对宠物的描述", required = false)
	private String feature;
	@ApiModelProperty(name = "type", value = "宠物的类型", required = false)
	private String type;
	private Date adoptTime;

	public Long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getImg() {
		return img;
	}

	public String getFeature() {
		return feature;
	}

	public void setFeature(String feature) {
		this.feature = feature;
	}

	public void setImg(String img) {
		this.img = img;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Long getOwnerId() {
		return ownerId;
	}

	public String getOwnerName() {
		return ownerName;
	}

	public void setOwnerId(Long ownerId) {
		this.ownerId = ownerId;
	}

	public void setOwnerName(String ownerName) {
		this.ownerName = ownerName;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
	public Date getAdoptTime() {
		return adoptTime;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
	public void setAdoptTime(Date adoptTime) {
		this.adoptTime = adoptTime;
	}

	public static PetDTO entityToDto(Pet entity, PetDTO dto) {
		dto.setId(entity.getId());
		dto.setName(entity.getName());
		dto.setFeature(entity.getFeature());
		dto.setImg(entity.getImg());
		dto.setType(entity.getType().getName());
		if (entity.getOwner() != null) {
			dto.setAdoptTime(entity.getAdoptTime());
			dto.setOwnerId(entity.getOwner().getId());
			dto.setOwnerName(entity.getOwner().getName());
		}
		return dto;
	}

	public static Pet dtoToEntity(Pet entity, PetDTO dto) {
		entity.setId(dto.getId());
		entity.setFeature(dto.getFeature());
		entity.setImg(dto.getImg());
		entity.setName(dto.getName());
		if (dto.getType().equals("狗")) {
			entity.setType(PetTypeEmun.DOG);
		} else if (dto.getType().equals("猫")) {
			entity.setType(PetTypeEmun.CAT);
		} else {
			entity.setType(PetTypeEmun.OTHER);
		}
		entity.setAdoptTime(dto.getAdoptTime());
		return entity;

	}
}
